package cn.xiaobai.controller;

import cn.xiaobai.domain.ExcelImport;
import cn.xiaobai.domain.TablePro;
import cn.xiaobai.server.ExcelToolServer;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author yangdaji
 * @Date 2024/3/21
 * @PackageName cn.xiaobai.controller
 * @ClassName Test
 */
@RestController
public class ExcelController {

    @Autowired
    private ExcelToolServer excelToolServer;

    @RequestMapping("/uploadFile")
    public ResponseEntity<TablePro> upload(ExcelImport excelImport) {
        return ResponseEntity.ofNullable(excelToolServer.dataImport(excelImport));
    }

    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public ResponseEntity<TablePro> listTable(String tableName) {
        return ResponseEntity.ofNullable(excelToolServer.queryTableByName(tableName));
    }

    @RequestMapping(value = "/getTableName", method = RequestMethod.GET)
    public ResponseEntity<List<String>> getTableName() {
        return ResponseEntity.ofNullable(excelToolServer.getTableAll());
    }
}
